﻿using KTD.Web.BLL;
using KTD.Web.Models.VD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XXS.Common.ControllerExt;

namespace KTD.Web.Controllers
{
    public class MemberController : Controller
    {
        // GET: Attachment
        public ActionResult Index(MemberQD im)
        {
            var res = MF.MemberManager.GetListBy(im);
            return View(res);
        }


        public ActionResult Admin(MemberQD im)
        {
            im.Type = "管理员";
            var res = MF.MemberManager.GetListBy(im);
            return View(res);
        }

        public ActionResult Detail(int Id)
        {

            ViewBag.Id = Id;
            var res = MF.MemberManager.Find(Id);
            return View(res);
        }


        [HttpPost]
        public ActionResult Create(MemberCUD im)
        {
            im.Type = "管理员";
            MF.MemberManager.Create(im);
            return this.JsonNet(new { succuess = true });
        }

        [HttpGet]
        public ActionResult Create()
        {
            var model = new MemberCUD();
            return View(model);
        }



        [HttpGet]
        public ActionResult Update(int Id)
        {
            var model = MF.MemberManager.Find(Id);
            return View(model);
        }


        public ActionResult Delete(int Id)
        {
            try
            {
                MF.MemberManager.Delete(Id);
                return this.JsonNet(new { success = true });
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message });
            }
        }


        public ActionResult Find(int Id)
        {
            try
            {
                var res = MF.MemberManager.Find(Id);
                return this.JsonNet(new { success = true, data = res }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }

        [HttpPost]
        public ActionResult Update(MemberCUD im)
        {
            try
            {
                MF.MemberManager.Update(im);
                return this.JsonNet(new { success = true });
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message });
            }
        }


        public ActionResult LikeHouse(LikeD im)
        {
            try
            {
                MF.MemberManager.LikeHouse(im);
                return this.JsonNet(new { success = true});
            }
            catch (Exception ex)
            {
                return this.JsonNet(new { success = false, msg = ex.Message });
            }
        }

     
    }
}